package com.zoho.aimei.task;

import com.zoho.aimei.service.SynService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@Configuration
@EnableScheduling
public class ScheduleTask {

    SynService synService;

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public ScheduleTask(SynService synService) {
        this.synService = synService;
    }

    // 每半小时执行一次
    @Scheduled(cron = "0 0/30 * * * ?")
    //@Scheduled(cron = "0/5 * * * * ?")
    public void testData() {
        log.info("-----开始【同步官方数据】定时任务 " + format.format(new Date()) + "-----");
        synService.synData();
        log.info("-----结束【同步官方数据】定时任务 " + format.format(new Date()) + "-----");
    }
}
